package service;

import java.util.List;


import common.DButil;
import vo.ScrapBean;




public class ScrapService {
	public  void insert(String bid,String uuser,int snum,String outtime,String sdetail,int state){
		String sql="insert into scrap(b_id,s_p_user,s_num,s_p_time,s_detail,s_state) values('"+bid+"','"+uuser+"',"+snum+",'"+outtime+"','"+sdetail+"',"+state+")";
		 String upsql="update book set b_num=b_num-"+snum+" where b_id='"+bid+"'";
			DButil db = DButil.getInstance();
			db.excuteUpdate(sql);
			db.excuteUpdate(upsql);
			db.close();
	}
	
	public  List<Object>  getAll(){
		String sql="select sc.s_id,sc.b_id,bk.b_name,sc.s_p_user,sc.s_num,sc.s_p_time,sc.s_detail,sc.s_state from scrap sc,book bk where sc.b_id=bk.b_id";
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,ScrapBean.class);
		db.close();
		return list;
	}
	public  List<Object> get(String user){
		String sql="select distinct sc.s_id,sc.b_id,bk.b_name,sc.s_p_user,sc.s_num,sc.s_p_time,sc.s_detail ,sc.s_state from scrap sc,book bk, user us where sc.b_id=bk.b_id  and s_p_user='"+user+"' ";
		DButil db = DButil.getInstance();
		List<Object> list=db.excuteQuery(sql,ScrapBean.class);
		db.close();
		return list;
	}
	public  void update(int sid,int state){
		String sql="update scrap set s_state='"+state+"' where s_id='"+sid+"'";
		DButil db = DButil.getInstance();
		db.excuteUpdate(sql);
		db.close();
	}
}
